﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary1.BLL;
using ClassLibrary1.DAL;

namespace TransactionCategoriser
{
    public partial class Form2 : Form
    {
        tTransaction ottransaction;

        Transaction otransaction = new Transaction();
        int iTransactionID = 0;
        public Form2()
        {
            InitializeComponent();
            ottransaction = otransaction.GetOldestNonCategorised();
            if (ottransaction != null)
            {
                lblDate.Text = ottransaction.Date.ToString();
                lblDescription.Text = ottransaction.Description;
                lblAmount.Text = ottransaction.Amount.ToString();
                lblAccount.Text = ottransaction.Account.AccountNumber.ToString();
                iTransactionID = ottransaction.TransactionID;
                foreach (string sCategory in otransaction.getCategories().OrderBy(c => c))
                {
                    listBox1.Items.Add(sCategory);
                }
            }

            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(!string.IsNullOrEmpty(textBox1.Text))
            {
                otransaction.newCategory(textBox1.Text);
                otransaction.AddCategory(iTransactionID, textBox1.Text);
            }
            foreach (object item in listBox1.SelectedItems)
            {
                otransaction.AddCategory(iTransactionID, item.ToString());
                
            }
            Close();
        }
    }
}
